"""
@Version: V1.0
@Author: wilson
@License: Apache Licence
@Contact: wevsmy@qq.com
@Site: http://wevsmy.cn
@Software: PyCharm
@File: GetBilibili404.py
@Time: 5/10 19:29
"""

from urllib import request
import json, os

def getHtml():
    url = "https://www.bilibili.com/activity/web/view/data/31"
    data = request.urlopen(url).read().decode("utf-8")
    return data


def downImg(url, fileName):
    with request.urlopen(url) as f:
        data = f.read()
        with open(str("img"+os.sep+fileName), mode="wb") as f:
            f.write(data)


def Main():
    data = getHtml()
    jsonDataList = json.loads(data)["data"]["list"]
    for i in jsonDataList:
        imgUrl = "http:" + i["data"]["img"]
        fileName = i["name"] + ".png"
        downImg(imgUrl, fileName)
        print("{}下载完成...".format(fileName))


if __name__ == '__main__':
    Main()
    pass